import { Route, Switch, NavLink, Link ,BrowserRouter,Redirect} from 'react-router-dom'
import {Suspense} from "react"
import QcEventEmitter from "../util/qcevents"
let RouterView = (props)=>{
    console.log(props)
    let {RouterList} = props
    console.log(RouterList)
    let routerList = RouterList.filter((item,index)=>{
        return !item.from
    })
    let redirect = RouterList.filter((item,index)=>{
        return item.from
    })[0]
    // console.log(redirect)
    return (
        <Suspense fallback={<div>...loading</div>}>
            <Switch>
                {
                    routerList&&routerList.length?routerList.map((item,index)=>{
                        // console.log(item)
                        return <Route path={item.path} key={index} render={(routerProps)=>{
                                console.log(routerProps,"routerProps")
                                window.withRouter = routerProps
                                // let aaa = window.localStorage.setItem("router",JSON.stringify(routerProps))
                                // setTimeout(()=>{console.log(aaa);},222)
                                // console.log(aaa,"aaa")


                                //QcEventEmitter.emit("zhao",routerProps)
                                return <item.component {...routerProps}></item.component>
                        }
                        }></Route>
                    }):""
                }
                {
                    redirect?<Redirect from={redirect.from} to={redirect.to}></Redirect>:"暂无重定向"
                }

            </Switch>
        </Suspense>
    )
}
export default RouterView